//
//  EFengOrganizationBaseView.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/2/18.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengOrganizationBaseView.h"
#import "CGroupModel.h"
#import "CContactModel.h"
#import "SettingNormalCell.h"
#import "GroupMenberCell.h"
#import "CXmppRequestMgr.h"
#import "UIImageView+WebCache.h"
#import "WZHeader.h"
#import "WZHeaderView.h"
#import "CCompanyMgr.h"
#import "CCompany.h"
#import "Masonry.h"
#import "NSArray+PinYin.h"
#import "CContactMgr.h"
@interface EFengOrganizationBaseView ()<UITableViewDataSource, UITableViewDelegate, WZHeaderViewDelegate>
@property (nonatomic, strong) WZHeader *kefuHeader;
@property (nonatomic, strong) WZHeader *waibuHeader;
@property (nonatomic, strong) WZHeader *changyongHeader;


@end


@implementation EFengOrganizationBaseView

- (WZHeader *)kefuHeader
{
    if (_kefuHeader == nil) {
        _kefuHeader = [[WZHeader alloc] init];
    }
    return _kefuHeader;
}

- (WZHeader *)waibuHeader
{
    if (_waibuHeader == nil) {
        _waibuHeader = [[WZHeader alloc] init];
    }
    return _waibuHeader;
}
- (WZHeader *)changyongHeader
{
    if (_changyongHeader == nil) {
        _changyongHeader = [[WZHeader alloc] init];
    }
    return _changyongHeader;
}



- (void)setMineGroupArray:(NSArray *)mineGroupArray
{
    _mineGroupArray = mineGroupArray;
    [self.tableView reloadData];
}

- (void)setOtherGroupArray:(NSArray *)otherGroupArray
{
    _otherGroupArray = otherGroupArray;
    [self.tableView reloadData];
}

- (void)setDiscussionArray:(NSArray *)discussionArray
{
    _discussionArray = discussionArray;

    [self.tableView reloadData];
}

- (void)setChangyongList:(NSArray *)changyongList
{
    _changyongList = changyongList;
    if (changyongList.count > 0) {
        self.changyongHeader.headerText = [NSString stringWithFormat:@"%@(%zd)",@"常用联系人",changyongList.count];
        self.changyongHeader.rowArray = changyongList;
        self.changyongHeader.isEdit = YES;
    }

    [self.tableView reloadData];
}

- (void)setKefuList:(NSArray *)kefuList
{
    _kefuList = kefuList;
    if (kefuList.count > 0) {
        self.kefuHeader.headerText = [NSString stringWithFormat:@"%@(%zd)",@"万朝客服",kefuList.count];
        self.kefuHeader.rowArray = kefuList;
        self.kefuHeader.isEdit = NO;
    }
    [self.tableView reloadData];
}

- (void)setWaibuList:(NSArray *)waibuList
{
    _waibuList = waibuList;
    if (waibuList.count > 0) {
        self.waibuHeader.headerText = [NSString stringWithFormat:@"%@(%zd)",@"外部联系人",waibuList.count];
        self.waibuHeader.isEdit = YES;
        self.waibuHeader.rowArray = waibuList;
    }
    [self.tableView reloadData];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.backgroundColor = ClearColor;
        self.isAnimation = YES;
        [self setupNoListView];
    }
    return self;
}


- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = ClearColor;
        _tableView.scrollEnabled = YES;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        [self addSubview:_tableView];
    }
    return _tableView;
}

- (void)setupNoListView
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = ClearColor;
    view.hidden = YES;
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(0);
    }];
    self.nolistView = view;

    UIImageView *imagView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BG-zero"]];
    [view addSubview:imagView];
    [imagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(140);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(100);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = ClearColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = Font16;
    label.textColor = RGBCOLORWITH16COLOR(0xb1b1b1);
    label.text = @"您还没有加入过群";
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imagView).mas_equalTo(100);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(20);
    }];
    self.noListLabel = label;
    
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.layer.cornerRadius = 3.0f;
    button1.layer.masksToBounds = YES;
    [button1 setTitle:@"创建讨论组" forState:UIControlStateNormal];
    button1.titleLabel.font = Font18;
    [button1 setTitleColor:WhiteColor forState:UIControlStateNormal];
    button1.backgroundColor = RGBCOLOR(89, 136, 243);
    [button1 addTarget:self action:@selector(createNewDiscuss) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button1];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label).mas_equalTo(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(40);
    }];
    self.createButton = button1;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger sections = 0;
    
    switch (self.type) {
        case organization:
        {
            sections = 1;
        }
            break;
        case group:
        {
            if (self.mineGroupArray.count > 0) {
                sections ++;
            }
            if (self.otherGroupArray.count > 0) {
                sections ++;
            }
        }
            break;
        case discuss:
        {
            sections = 1;
        }
            break;
        case mineContact:
        {
            if (self.kefuList.count > 0) {
                sections ++;
            }
            if (self.waibuList.count > 0) {
                sections ++;
            }
            if (self.changyongList.count > 0) {
                sections ++;
            }
            
        }
            break;
            
        default:
            break;
    }
    return sections;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger rows = 0;
    switch (self.type) {
        case organization:
        {
            
        }
            break;
        case group:
        {
            if (section == 0) {
                if (self.mineGroupArray.count > 0) {
                    rows = self.mineGroupArray.count;
                } else {
                    rows = self.otherGroupArray.count;
                }
            } else if (section == 1) {
                rows = self.otherGroupArray.count;
            } else {
                rows = 0;
            }
        }
            break;
        case discuss:
        {
            rows = self.discussionArray.count;
        }
            break;
        case mineContact:
        {
            
            WZHeader *header = [self header:section];
            if (header.isOpen) {
                rows = header.rowArray.count;
            } else {
                rows = 0;
            }
            
            
        }
            break;
            
        default:
            break;
    }
    return rows;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 0;
    switch (self.type) {
        case organization:
        {
            height = 0.0f;
        }
            break;
        case group:
        {
            height = 60.0f;
        }
            break;
        case discuss:
        {
            height = 60.0f;
        }
            break;
        case mineContact:
        {
            
            height = 60.0f;
        }
            break;
            
        default:
            break;
    }
    return height;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    CGFloat height = 0;
    switch (self.type) {
        case organization:
        {
            height = 0.01f;
        }
            break;
        case group:
        {
            height = 35.0f;
        }
            break;
        case discuss:
        {
            height = 0.01f;
        }
            break;
        case mineContact:
        {
            
            height = 35.0f;
        }
            break;
            
        default:
            break;
    }
    return height;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section   // custom view for header. will be adjusted to default or specified header height
{
    UIView *headerView = nil;
    switch (self.type) {
        case organization:
        {
            
        }
            break;
        case group:
        {
            headerView = [[UIView alloc] init];
            headerView.frame = CGRectMake(0, 0, tableView.frame.size.width, 35.0f);
            headerView.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
            UIView *beginLine = [[UIView alloc] init];
            beginLine.frame = CGRectMake(0, 0, tableView.frame.size.width, 0.5);
            [beginLine setBackgroundColor:KSEPERATORLINECOLOR];
            [headerView addSubview:beginLine];
            
            UIView *endLine = [[UIView alloc] init];
            endLine.frame = CGRectMake(0, 35.0f-0.5, tableView.frame.size.width, 0.5);
            [endLine setBackgroundColor:KSEPERATORLINECOLOR];
            [headerView addSubview:endLine];
            
            UILabel *label = [[UILabel alloc] init];
            if (section == 0) {
                if (self.mineGroupArray.count > 0) {
                    [label setText:[NSString stringWithFormat:@"我创建的群(%zd)",self.mineGroupArray.count]];
                } else {
                    [label setText:[NSString stringWithFormat:@"我加入的群(%zd)",self.otherGroupArray.count]];
                }
            } else {
                [label setText:[NSString stringWithFormat:@"我加入的群(%zd)",self.otherGroupArray.count]];
            }
            label.frame = CGRectMake(15, 1, 200, 35.0f-1);
            [label setTextColor:RGBCOLOR(0x92, 0x92, 0x92)];
            [headerView addSubview:label];
            
        }
            break;
        case discuss:
        {
            
        }
            break;
        case mineContact:
        {
            WZHeaderView *header = [WZHeaderView WZHeaderViewWithTableView:tableView];
            header.header = [self header:section];
            header.WZHeaderViewDelegate = self;
            headerView = header;
            
        }
            break;
            
        default:
            break;
    }
    
    return headerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section   // custom view for footer. will be adjusted to default or specified footer height
{
    return nil;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (self.type) {
        case organization:
        {
            return UITableViewCellEditingStyleNone;
        }
            break;
        case group:
        {
            return UITableViewCellEditingStyleNone;
        }
            break;
        case discuss:
        {
            return UITableViewCellEditingStyleNone;
        }
            break;
        case mineContact:
        {
            WZHeader *header = [self header:indexPath.section];
            if (header.isEdit) {
                return UITableViewCellEditingStyleDelete;
            } else {
                return UITableViewCellEditingStyleNone;
            }
        }
            break;
        default:
        {
            return UITableViewCellEditingStyleNone;
        }
            break;
    }
    
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        if ([self.EFengOrganizationBaseViewDelegate respondsToSelector:@selector(eFengOrganizationBaseViewDidCommitEdittingWithContact:group:)] && self.EFengOrganizationBaseViewDelegate != nil) {
            WZHeader *header = [self header:indexPath.section];
            if ([header.headerText hasPrefix:@"常用"]) {
                CContactModel *contact = self.changyongList[indexPath.row];
                [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidCommitEdittingWithContact:contact group:nil];
            }
            if ([header.headerText hasPrefix:@"外部"]) {
                CContactModel *contact = self.waibuList[indexPath.row];
                [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidCommitEdittingWithContact:contact group:nil];            }
           
        }
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
    
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (self.type) {
        case organization:
        {
            return NO;
        }
            break;
        case group:
        {
            return NO;
        }
            break;
        case discuss:
        {
            return NO;
        }
            break;
        case mineContact:
        {
            WZHeader *header = [self header:indexPath.section];
            return header.isEdit;
        }
            break;
        default:
        {
            return NO;
        }
            break;
    }
    
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0)
{
    return @"删除";
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    switch (self.type) {
        case organization:
        {
            
        }
            break;
        case group:
        {
            
            CGroupModel *groupModel = nil;
            if (indexPath.section == 0) {
                if (self.mineGroupArray.count > 0) {

                    groupModel = self.mineGroupArray[indexPath.row];
                } else {
                    
                    groupModel = self.otherGroupArray[indexPath.row];
                }
            } else {
          
                groupModel = self.otherGroupArray[indexPath.row];
            }
            
            
            static NSString *NormalCellIdentifier = @"SettingNormalCell";
            SettingNormalCell *normalCell = [tableView dequeueReusableCellWithIdentifier:NormalCellIdentifier];
            if (normalCell == nil) {
                normalCell = [[[NSBundle mainBundle] loadNibNamed:@"SettingNormalCell" owner:self options:nil] objectAtIndex:0];
            }
            
            [normalCell.icon setImage:[UIImage imageNamed:[self iconName:indexPath]] forState:UIControlStateNormal];
            normalCell.icon.layer.cornerRadius = 5.0f/2;
            normalCell.icon.layer.masksToBounds = YES;
            [normalCell.titleLabel setText:[NSString stringWithFormat:@"%@(%zd)",groupModel.GroupName,groupModel.UserNum]];
            [normalCell.seperatorLine setHidden:NO];
            normalCell.rightArrow.hidden = YES;
            //    if(indexPath.section == 1 && indexPath.row == 0)
            //    {
            //    }
            //    else
            //    {
            //        [normalCell.seperatorLine setHidden:YES];
            //    }
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell = normalCell;
            
        }
            break;
        case discuss:
        {
            CGroupModel *groupModel = nil;
            groupModel = self.discussionArray[indexPath.row];
            static NSString *NormalCellIdentifier = @"SettingNormalCell";
            SettingNormalCell *normalCell = [tableView dequeueReusableCellWithIdentifier:NormalCellIdentifier];
            if (normalCell == nil) {
                normalCell = [[[NSBundle mainBundle] loadNibNamed:@"SettingNormalCell" owner:self options:nil] objectAtIndex:0];
            }
            
            [normalCell.icon setImage:[UIImage imageNamed:[self iconName:indexPath]] forState:UIControlStateNormal];
            normalCell.icon.layer.cornerRadius = 5.0f/2;
            normalCell.icon.layer.masksToBounds = YES;
            NSString *nameStr = [groupModel.GroupName stringByReplacingOccurrencesOfString:@"," withString:@"、"];
            [normalCell.titleLabel setText:[NSString stringWithFormat:@"%@(%zd)",nameStr,groupModel.UserNum]];
            [normalCell.seperatorLine setHidden:NO];
            normalCell.rightArrow.hidden = YES;
            cell.accessoryType = UITableViewCellAccessoryNone;
            //bug 8665 fixed by lixu
            normalCell.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
            cell = normalCell;
            
        }
            break;
        case mineContact:
        {
            
            WZHeader *header = [self header:indexPath.section];
            CContactModel *contact = header.rowArray[indexPath.row];
            static NSString *NormalCellIdentifier = @"GroupMenberCell";
            GroupMenberCell *groupMemberCell = [tableView dequeueReusableCellWithIdentifier:NormalCellIdentifier];
            if (groupMemberCell == nil) {
                groupMemberCell = [[[NSBundle mainBundle] loadNibNamed:@"GroupMenberCell" owner:self options:nil] objectAtIndex:0];
            }
            if ([contact.yuLiuZiduan3 isEqualToString:@"isKefu"]) {
                [groupMemberCell.icon setImage:[UIImage imageNamed:@"head-kefu"]];
            } else {
                [groupMemberCell.icon sd_setImageWithURL:[NSURL URLWithString:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:contact.UserID]] placeholderImage:[UIImage imageNamed:@"80-80"]];
            }
            if ([contact.yuLiuZiduan3 isEqualToString:@"isWaibu"]) {
                CCompany *company = [[[CCompanyMgr alloc]init] loadCompanyWithcompCode:contact.compCode];
                if (company) {
                    [groupMemberCell.titleLabel setText:[NSString stringWithFormat:@"%@ (%@)",contact.UserName,company.yuLiuZiduan1]];
                }
                else
                {
                    [groupMemberCell.titleLabel setText:[NSString stringWithFormat:@"%@ (loading...)",contact.UserName]];
                    __weak typeof(self) weakSelf = self;
                    [[CXmppRequestMgr shareInstance] getUserInfoWithUserCode:contact.UserCode AndsuccessHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                        BOOL ret;
                        CCompany *newCompany = [[CCompany alloc]init];
                        newCompany.compCode = responseObject[@"companyId"];
                        newCompany.yuLiuZiduan1 = responseObject[@"companyName"];
                        ret =  [[[CCompanyMgr alloc]init] insetCompany:newCompany];
                    
                        contact.address = responseObject[@"address"];
                        contact.Autograph = responseObject[@"autograph"];
                        contact.birthDay = responseObject[@"birthday"];
                        contact.compCode = responseObject[@"companyId"];
                        contact.Telephone = responseObject[@"telephone"];
                        contact.Email = responseObject[@"email"];
                        contact.MobileTelephone = responseObject[@"mobilePhone"];
                        contact.Position = responseObject[@"position"];
                        contact.UserName = responseObject[@"realName"];
                        contact.SEX = responseObject[@"sex"];
                         ret = [[[CContactMgr alloc]init] updateContact:contact];
                        if (ret) {
                                [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
                        }
                    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                        
                    }];
                }
            }
            else
            {
                [groupMemberCell.titleLabel setText:contact.UserName];

            }
            groupMemberCell.Arrow.hidden = NO;
            NSInteger rows = [tableView numberOfRowsInSection:indexPath.section];
            if(indexPath.row == rows - 1)
            {
                [groupMemberCell.seperatorLine setHidden:YES];
            } else {
                groupMemberCell.seperatorLine.hidden = NO;
            }
            cell = groupMemberCell;
            
        }
            break;
        default:
        {
            
        }
            break;
    }
    
    return cell;
}

-(WZHeader *)header:(NSInteger)section
{
    WZHeader *header = nil;
    switch (section) {
        case 0:
        {
            if (self.kefuList.count > 0) {
                header = self.kefuHeader;
            } else if (self.waibuList.count > 0) {
                header = self.waibuHeader;
            } else if (self.changyongList.count > 0){
                header = self.changyongHeader;
            }
        }
            break;
        case 1:
        {
            if (self.kefuList.count <= 0) {
                header = self.changyongHeader;
            } else {
                if (self.waibuList.count > 0) {
                    header = self.waibuHeader;
                } else {
                    header = self.changyongHeader;
                }
            }
        }
            break;
        case 2:
        {
            header = self.changyongHeader;
        }
            break;
        default:
            break;
    }
    return header;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    switch (self.type) {
        case organization:
        {
            
        }
            break;
        case group:
        {
            
            
            if ([self.EFengOrganizationBaseViewDelegate respondsToSelector:@selector(eFengOrganizationBaseViewDidSelectedWithContact:group:)] && self.EFengOrganizationBaseViewDelegate != nil) {
                
                CGroupModel *model = nil;
                if (indexPath.section == 0) {
                    if (self.mineGroupArray.count > 0) {
                       
                        model = self.mineGroupArray[indexPath.row];
                    } else {
                        
                        model = self.otherGroupArray[indexPath.row];
                    }
                } else {
               
                    model = self.otherGroupArray[indexPath.row];
                }
    
                [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidSelectedWithContact:nil group:model];
                
            }
        }
            break;
        case discuss:
        {
            if ([self.EFengOrganizationBaseViewDelegate respondsToSelector:@selector(eFengOrganizationBaseViewDidSelectedWithContact:group:)] && self.EFengOrganizationBaseViewDelegate != nil) {
                CGroupModel *model = nil;
             
                model = self.discussionArray[indexPath.row];
                [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidSelectedWithContact:nil group:model];
                
            }
        }
            break;
        case mineContact:
        {
            
            if ([self.EFengOrganizationBaseViewDelegate respondsToSelector:@selector(eFengOrganizationBaseViewDidSelectedWithContact:group:)] && self.EFengOrganizationBaseViewDelegate != nil) {
                WZHeader *header = [self header:indexPath.section];
                CContactModel *contact = header.rowArray[indexPath.row];

                [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidSelectedWithContact:contact group:nil];
                
            }
            
        }
        default:
        {
            
        }
            break;
    }
    
}


-(NSString *)iconName:(NSIndexPath *)indexPath
{
    NSString *iconName = nil;
    switch (self.type) {
        case group:
        {
            iconName = @"icon_groupList";
        }
            break;
        case discuss:
        {
            iconName = @"icon-discussList";
        }
            break;
        default:
            break;
    }
    
    return iconName;
}

- (void)createNewDiscuss
{
    if ([self.EFengOrganizationBaseViewDelegate respondsToSelector:@selector(eFengOrganizationBaseViewDidCreateDisscussion)] && self.EFengOrganizationBaseViewDelegate != nil) {
        [self.EFengOrganizationBaseViewDelegate eFengOrganizationBaseViewDidCreateDisscussion];
    }
}

- (void)WZHeaderViewDidClick:(WZHeader *)header
{
    header.isOpen = !header.isOpen;
    [self.tableView reloadData];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.nolistView.frame = CGRectMake(0, 0, self.width, self.height);
    self.tableView.frame = CGRectMake(0, 0, self.width, self.height);
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isAnimation) {
        cell.transform =  CGAffineTransformMakeTranslation(HARDWARE_SCREEN_WIDTH, 0);
        [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
            cell.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished){
            if (finished) {
                _isAnimation = NO;
            }
        }];
    }

}
@end
